<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: last_viewed.php 140 2013-09-22 07:44:23Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 140 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-22 07:44:23 +0000 (Sun, 22 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

if (isset($_SESSION['tracking']['products_history'][0])) {
	$box_smarty = new smarty;
	$box_smarty->assign('tpl_path','templates/'.CURRENT_TEMPLATE.'/');
	$box_smarty->assign('html_tpl_path', CURRENT_TEMPLATE.'/html');
	
	$list_data = get_list_data('last_viewed');

	if($list_data['box_count'] > 1) {
		for($i=0;$i<count($_SESSION['tracking']['products_history']);$i++)
			$productIDs[] = $_SESSION['tracking']['products_history'][$i];
		$where_in = " AND p.products_id IN ('".implode("','",$productIDs)."') ";
	} else
		$where_in = " AND p.products_id = '".(int)$_SESSION['tracking']['products_history'][0]."' ";

	if($last_viewed = $db->db_query_limit("SELECT
												p.products_id,
												pd.products_name,
												p.products_price,
												p.products_tax_class_id,
												p.products_image,
												p.products_vpe,
												p.products_vpe_status,
												p.products_vpe_value,
												p.products_fsk18
											FROM
												".TABLE_PRODUCTS." p 
												LEFT JOIN ".TABLE_PRODUCTS_DESCRIPTION." AS pd
												ON (pd.products_id = p.products_id AND pd.language_id = '".$_SESSION['languages_id']."')
											WHERE
												p.products_status = '1'
												".$where_in."
												".$product->groupCheck().$product->fsk18(), $list_data['box_count'])) {

		while(!$last_viewed->EOF) { $rows ++;
			$getCat = $db->db_query("SELECT 
										c.categories_id, 
										cd.categories_name 
									FROM 
										".TABLE_CATEGORIES." c
										LEFT JOIN ".TABLE_CATEGORIES_DESCRIPTION." cd
										ON (cd.categories_id = c.categories_id AND cd.language_id = '".$_SESSION['languages_id']."'),
										".TABLE_PRODUCTS_TO_CATEGORIES." p2c
									WHERE
										p2c.categories_id = '".$last_viewed->fields['products_id']."'
									AND
										c.categories_id = p2c.categories_id");

			$cat_name_tmp[$rows] = array('CATEGORIES_NAME' => $getCat->fields['categories_name'],
										'CATEGORIES_LINK' => href_link(FILENAME_DEFAULT, 'cPath='.$getCat->fields['categories_id']));

			$last_viewed_tmp[$rows] = $product->buildDataArray($last_viewed->fields, 'thumbnail', $list_data, $rows, 172);
			$last_viewed_content[$rows] = array_merge($last_viewed_tmp[$rows], $cat_name_tmp[$rows]);

			$last_viewed->MoveNext();
		}

		$box_smarty->assign('last_viewed_content', $last_viewed_content);
		$box_smarty->assign('MY_PAGE', TEXT_MY_PAGE);
		$box_smarty->assign('MY_PERSONAL_PAGE', href_link(FILENAME_ACCOUNT));
		$box_smarty->assign('language', $_SESSION['language']);
		
		if($last_viewed->_numOfRows > 1 && $list_data['box_effect'] != 'none') {
			$get[] = 'lv='.$list_data['box_effect'];
			$get[] = 'lvd='.$list_data['effect_direction'];
		}
		
		if (!CacheCheck()) {
			$box_smarty->caching = false;
			$box_content= $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_last_viewed.html');

		} else {
			$box_smarty->caching = true;
			$box_smarty->cache_lifetime=CACHE_LIFETIME;
			$box_smarty->cache_modified_check=CACHE_CHECK;
			$cache_id = 'box_last_viewed_'.$_SESSION['language'].'_'.$_SESSION['customers_status']['customers_status_name'];
			$box_content = $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_last_viewed.html',$cache_id);
		}
	}
}